package zelix.hack.hacks;

import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBucketMilk;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemPotion;
import net.minecraft.network.play.client.CPacketPlayer;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import zelix.eventapi.events.Event;
import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.utils.Wrapper;
import zelix.utils.system.Mapping;
import zelix.value.BooleanValue;
import zelix.value.Mode;
import zelix.value.ModeValue;

import java.lang.reflect.Field;

public class FastUse extends Hack {

    Number ticks = 0.49D;
    BooleanValue onGround;
    ModeValue mode;

    public static Boolean  eated = false;

    public FastUse() {
        super("FastUse", HackCategory.PLAYER);
        this.mode = new ModeValue("Mode" , new Mode("HytTimer" , true));
        this.onGround = new BooleanValue("OnGround" , true);
        this.addValue(mode , onGround);
    }


    @Override
    public void onEnable() {
        super.onEnable();
    }

    @Override
    public void onDisable() {
        setTickLength(50);
        super.onDisable();
    }
    @Override
    public void onPlayerTick(TickEvent.PlayerTickEvent event) {
        if (mode.getMode("HytTimer").isToggled()){
            if (Wrapper.INSTANCE.player().isHandActive() && !Wrapper.INSTANCE.player().isRiding()){
            if (onGround.getValue()){
                if (Wrapper.INSTANCE.player().isHandActive() && !Wrapper.INSTANCE.player().isRiding()){
                    setTickLength(50 / ticks.floatValue());
                    String check = null;

                    for (int n3 = 2, j = 0 ; j < n3; ++j) {
                        final int it = j;
                        final int n4 = 0;

                            Wrapper.INSTANCE.sendPacket(new CPacketPlayer(Wrapper.INSTANCE.player().onGround));

                    }
                }
            }else {
                setTickLength(50 / ticks.floatValue());

                for (int n3 = 2, j = 0; j < n3; ++j) {
                    final int it = j;
                    final int n4 = 0;
                    Wrapper.INSTANCE.sendPacket(new CPacketPlayer(Wrapper.INSTANCE.player().onGround));
                    break;
                }
               // setTickLength(50);
            }
        }
    }
}

    private void setTickLength(float tickLength)
    {
        try
        {
            Field fTimer = Minecraft.getMinecraft().getClass().getDeclaredField(Mapping.timer);
            fTimer.setAccessible(true);

            Field fTickLength = net.minecraft.util.Timer.class.getDeclaredField(Mapping.tickLength);
            fTickLength.setAccessible(true);
            fTickLength.setFloat(fTimer.get(Minecraft.getMinecraft()), tickLength);

        }catch(ReflectiveOperationException e)
        {
            throw new RuntimeException(e);
        }
    }
}
